﻿namespace HCRS.Implementation
{
    using HCRS.DBACL;
    using System;
    using System.Data;
    using System.Runtime.InteropServices;

    /// <summary>
    /// 数据库操作实现 2008-2-16 by Field
    /// </summary>
    public class CommonDataAccess
    {
        /// <summary>
        /// 数据删除
        /// </summary>
        /// <param name="SQL">SQL语句</param>
        /// <param name="msg">输出信息</param>
        /// <returns>是否成功删除</returns>
        public static bool Delete(string SQL, out string msg)
        {
            return new DataAccessLayer().Delete(SQL, out msg);
        }

        /// <summary>
        /// 执行删除存储过程
        /// </summary>
        /// <param name="ProcedureName">存储过程</param>
        /// <param name="parameters">参数数组</param>
        /// <param name="ParaType">参数数据类型数组（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="ParaValue">参数值对象数组</param>
        /// <returns>是否成功执行</returns>
        public static bool ExecDeleteProcedure(string ProcedureName, string[] parameters, string[] ParaType, object[] ParaValue)
        {
            string msg = "";
            return (ExecProcedure(AccessCommand.Delete, ProcedureName, parameters, ParaType, ParaValue, out msg) > 0);
        }

        /// <summary>
        /// 执行删除存储过程
        /// </summary>
        /// <param name="commandtype">执行删除存储过程</param>
        /// <param name="ProcedureName">存储过程</param>
        /// <param name="parameters">参数数组</param>
        /// <param name="ParaType">参数数据类型数组（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="ParaValue">参数值对象数组</param>
        /// <param name="msg">输出信息</param>   
        /// <returns>影响行数</returns>
        public static int ExecDeleteProcedure(string ProcedureName, string[] parameters, string[] ParaType, object[] ParaValue, out string msg)
        {
            return ExecProcedure(AccessCommand.Delete, ProcedureName, parameters, ParaType, ParaValue, out msg);
        }

        /// <summary>
        /// 执行删除
        /// </summary>
        /// <param name="DBTable">数据库表名</param>
        /// <param name="parameters">Where条件字段数组</param>
        /// <param name="ParaValue">Where条件字段值对象数组</param>
        /// <returns>是否成功执行</returns>
        public static bool ExecDeleteSQL(string DBTable, string[] parameters, object[] ParaValue)
        {
            string msg = "";
            return (ExecDeleteSQL(DBTable, parameters, ParaValue, out msg) > 0);
        }

        /// <summary>
        /// 执行删除(带参数)
        /// </summary>
        /// <param name="DBTable">数据库表名</param>
        /// <param name="parameters">Where条件字段名(用“,”隔开)</param>
        /// <param name="ParaValue">Where条件字段值对象数组</param>
        /// <returns>影响行数</returns>
        public static bool ExecDeleteSQL(string DBTable, string parameters, object[] ParaValue)
        {
            return ExecDeleteSQL(DBTable, parameters.Split(new char[] { ',' }), ParaValue);
        }

        /// <summary>
        /// 执行删除(带参数)
        /// </summary>
        /// <param name="DBTable">数据库表名</param>
        /// <param name="parameters">Where条件字段名(用“,”隔开)</param>
        /// <param name="ParaType">Where条件字段数据类型(用“,”隔开)（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="ParaValue">Where条件字段值对象数组</param>
        /// <returns>影响行数</returns>
        public static bool ExecDeleteSQL(string DBTable, string parameters, string ParaType, object[] ParaValue)
        {
            return ExecDeleteSQL(DBTable, parameters.Split(new char[] { ',' }), ParaType.Split(new char[] { ',' }), ParaValue);
        }

        /// <summary>
        /// 执行删除(带参数)
        /// </summary>
        /// <param name="DBTable">数据库表名</param>
        /// <param name="parameters">Where条件字段名(用“,”隔开)</param>
        /// <param name="ParaValue">Where条件字段值对象数组</param>
        /// <param name="msg">输出信息</param>   
        /// <returns>影响行数</returns>
        public static int ExecDeleteSQL(string DBTable, string parameters, object[] ParaValue, out string msg)
        {
            return ExecDeleteSQL(DBTable, parameters.Split(new char[] { ',' }), ParaValue, out msg);
        }

        /// <summary>
        /// 执行删除(带参数)
        /// </summary>
        /// <param name="DBTable">数据库表名</param>
        /// <param name="parameters">Where条件字段数组</param>
        /// <param name="ParaValue">Where条件字段值对象数组</param>
        /// <param name="msg">输出信息</param>   
        /// <returns>影响行数</returns>
        public static int ExecDeleteSQL(string DBTable, string[] parameters, object[] ParaValue, out string msg)
        {
            return new DataAccessLayer().ExecDeleteSQL(DBTable, parameters, ParaValue, out msg);
        }

        /// <summary>
        /// 执行删除
        /// </summary>
        /// <param name="DBTable">数据库表名</param>
        /// <param name="parameters">Where条件字段数组</param>
        /// <param name="ParaType">Where条件字段数据类型数组（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="ParaValue">Where条件字段值对象数组</param>
        /// <returns>是否成功执行</returns>
        public static bool ExecDeleteSQL(string DBTable, string[] parameters, string[] ParaType, object[] ParaValue)
        {
            string msg = "";
            return (ExecDeleteSQL(DBTable, parameters, ParaType, ParaValue, out msg) > 0);
        }

        /// <summary>
        /// 执行删除(带参数)
        /// </summary>
        /// <param name="DBTable">数据库表名</param>
        /// <param name="parameters">Where条件字段数组</param>
        /// <param name="ParaType">Where条件字段数据类型数组（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="ParaValue">Where条件字段值对象数组</param>
        /// <param name="msg">输出信息</param>   
        /// <returns>影响行数</returns>
        public static int ExecDeleteSQL(string DBTable, string[] parameters, string[] ParaType, object[] ParaValue, out string msg)
        {
            return new DataAccessLayer().ExecDeleteSQL(DBTable, parameters, ParaType, ParaValue, out msg);
        }

        /// <summary>
        /// 执行删除(带参数)
        /// </summary>
        /// <param name="DBTable">数据库表名</param>
        /// <param name="parameters">Where条件字段名(用“,”隔开)</param>
        /// <param name="ParaType">Where条件字段数据类型(用“,”隔开)（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="ParaValue">Where条件字段值对象数组</param>
        /// <param name="msg">输出信息</param>   
        /// <returns>影响行数</returns>
        public static int ExecDeleteSQL(string DBTable, string parameters, string ParaType, object[] ParaValue, out string msg)
        {
            return ExecDeleteSQL(DBTable, parameters.Split(new char[] { ',' }), ParaType.Split(new char[] { ',' }), ParaValue, out msg);
        }

        /// <summary>
        /// 执行增删改存储过程
        /// </summary>
        /// <param name="ProcedureName">存储过程</param>
        /// <param name="parameters">用","隔开的参数</param>
        /// <param name="ParaType">用","隔开的参数数据类型（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="ParaValue">参数值对象数组</param>
        /// <returns>是否成功执行</returns>
        public static bool ExecInsertProcedure(string ProcedureName, string parameters, string ParaType, object[] ParaValue)
        {
            string msg = "";
            return (ExecProcedure(AccessCommand.Insert, ProcedureName, parameters.Split(new char[] { ',' }), ParaType.Split(new char[] { ',' }), ParaValue, out msg) > 0);
        }

        /// <summary>
        /// 执行增删改存储过程
        /// </summary>
        /// <param name="ProcedureName">存储过程</param>
        /// <param name="parameters">参数数组</param>
        /// <param name="ParaType">参数数据类型数组（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="ParaValue">参数值对象数组</param>
        /// <returns>是否成功执行</returns>
        public static bool ExecInsertProcedure(string ProcedureName, string[] parameters, string[] ParaType, object[] ParaValue)
        {
            string msg = "";
            return (ExecProcedure(AccessCommand.Insert, ProcedureName, parameters, ParaType, ParaValue, out msg) > 0);
        }

        /// <summary>
        /// 执行添加存储过程
        /// </summary>
        /// <param name="commandtype">执行添加存储过程</param>
        /// <param name="ProcedureName">存储过程</param>
        /// <param name="parameters">参数数组</param>
        /// <param name="ParaType">参数数据类型数组（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="ParaValue">参数值对象数组</param>
        /// <param name="msg">输出信息</param>   
        /// <returns>影响行数</returns>
        public static int ExecInsertProcedure(string ProcedureName, string[] parameters, string[] ParaType, object[] ParaValue, out string msg)
        {
            return ExecProcedure(AccessCommand.Insert, ProcedureName, parameters, ParaType, ParaValue, out msg);
        }

        /// <summary>
        /// 执行增加(带参数)
        /// </summary>
        /// <param name="DBTable">数据库表名</param>
        /// <param name="parameters">字段数组</param>
        /// <param name="ParaValue">字段值对象数组</param>
        /// <returns>是否成功执行</returns>
        public static bool ExecInsertSQL(string DBTable, string[] parameters, object[] ParaValue)
        {
            string msg = "";
            return (ExecInsertSQL(DBTable, parameters, ParaValue, out msg) > 0);
        }

        /// <summary>
        /// 执行增加(带参数)
        /// </summary>
        /// <param name="DBTable">数据库表名</param>
        /// <param name="parameters">字段名(用“,”隔开)</param>
        /// <param name="ParaValue">字段值对象数组</param>
        /// <param name="msg">输出信息</param>   
        /// <returns>影响行数</returns>
        public static bool ExecInsertSQL(string DBTable, string parameters, object[] ParaValue)
        {
            return ExecInsertSQL(DBTable, parameters.Split(new char[] { ',' }), ParaValue);
        }

        /// <summary>
        /// 执行增加(带参数)
        /// </summary>
        /// <param name="DBTable">数据库表名</param>
        /// <param name="parameters">字段数组</param>
        /// <param name="ParaValue">字段值对象数组</param>
        /// <param name="msg">输出信息</param>   
        /// <returns>影响行数</returns>
        public static int ExecInsertSQL(string DBTable, string[] parameters, object[] ParaValue, out string msg)
        {
            return new DataAccessLayer().ExecInsertSQL(DBTable, parameters, ParaValue, out msg);
        }

        /// <summary>
        /// 执行增加(带参数)
        /// </summary>
        /// <param name="DBTable">数据库表名</param>
        /// <param name="parameters">字段名(用“,”隔开)</param>
        /// <param name="ParaType">字段数据类型数组（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="ParaValue">字段值对象数组</param>
        /// <param name="msg">输出信息</param>   
        /// <returns>影响行数</returns>
        public static bool ExecInsertSQL(string DBTable, string parameters, string ParaType, object[] ParaValue)
        {
            return ExecInsertSQL(DBTable, parameters.Split(new char[] { ',' }), ParaType.Split(new char[] { ',' }), ParaValue);
        }

        /// <summary>
        /// 执行增加(带参数)
        /// </summary>
        /// <param name="DBTable">数据库表名</param>
        /// <param name="parameters">字段数组</param>
        /// <param name="ParaType">字段数据类型数组（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="ParaValue">字段值对象数组</param>
        /// <returns>是否成功执行</returns>
        public static bool ExecInsertSQL(string DBTable, string[] parameters, string[] ParaType, object[] ParaValue)
        {
            string msg = "";
            return (ExecInsertSQL(DBTable, parameters, ParaType, ParaValue, out msg) > 0);
        }

        /// <summary>
        /// 执行增加(带参数)
        /// </summary>
        /// <param name="DBTable">数据库表名</param>
        /// <param name="parameters">字段名(用","隔开)</param>
        /// <param name="ParaValue">字段值对象数组</param>
        /// <param name="msg">输出信息</param>   
        /// <returns>影响行数</returns>
        public static int ExecInsertSQL(string DBTable, string parameters, object[] ParaValue, out string msg)
        {
            return ExecInsertSQL(DBTable, parameters.Split(new char[] { ',' }), ParaValue, out msg);
        }

        /// <summary>
        /// 执行增加(带参数)
        /// </summary>
        /// <param name="DBTable">数据库表名</param>
        /// <param name="parameters">字段名(用","隔开)</param>
        /// <param name="ParaType">字段数据类型(用","隔开)（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="ParaValue">字段值对象数组</param>
        /// <param name="msg">输出信息</param>   
        /// <returns>影响行数</returns>
        public static int ExecInsertSQL(string DBTable, string parameters, string ParaType, object[] ParaValue, out string msg)
        {
            return ExecInsertSQL(DBTable, parameters.Split(new char[] { ',' }), ParaType.Split(new char[] { ',' }), ParaValue, out msg);
        }

        /// <summary>
        /// 执行增加(带参数)
        /// </summary>
        /// <param name="DBTable">数据库表名</param>
        /// <param name="parameters">字段数组</param>
        /// <param name="ParaType">字段数据类型数组（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="ParaValue">字段值对象数组</param>
        /// <param name="msg">输出信息</param>   
        /// <returns>影响行数</returns>
        public static int ExecInsertSQL(string DBTable, string[] parameters, string[] ParaType, object[] ParaValue, out string msg)
        {
            return new DataAccessLayer().ExecInsertSQL(DBTable, parameters, ParaType, ParaValue, out msg);
        }

        /// <summary>
        /// 执行存储过程(无参数)
        /// </summary>
        /// <param name="ProcedureName">存储过程名</param>
        /// <returns>DataSet</returns>
        public static DataSet ExecProcedure(string ProcedureName)
        {
            return new DataAccessLayer().ExecProcedure(ProcedureName);
        }

        /// <summary>
        /// 执行存储过程(无参数)
        /// </summary>
        /// <param name="ProcedureName">存储过程名</param>
        /// <param name="TableName">DataTable名</param>
        /// <returns>DataTable</returns>
        public static DataTable ExecProcedure(string ProcedureName, string TableName)
        {
            return new DataAccessLayer().ExecProcedure(ProcedureName, TableName);
        }

        /// <summary>
        /// 执行查询存储过程(带参数)
        /// </summary>
        /// <param name="ProcedureName">存储过程名</param>
        /// <param name="parameters">参数数组</param>
        /// <param name="ParaType">参数数据类型数组（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="ParaValue">参数值对象数组</param>
        /// <returns>数据集</returns>
        public static DataSet ExecProcedure(string ProcedureName, string[] parameters, string[] ParaType, object[] ParaValue)
        {
            return new DataAccessLayer().ExecProcedure(ProcedureName, parameters, ParaType, ParaValue);
        }

        /// <summary>
        /// 执行查询存储过程(带参数)
        /// </summary>
        /// <param name="ProcedureName">存储过程名</param>
        /// <param name="parameters">参数(用“,”隔开)</param>
        /// <param name="ParaType">数据类型(用“,”隔开)（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="ParaValue">参数值对象数组</param>
        /// <returns>数据集</returns>
        public static DataSet ExecProcedure(string ProcedureName, string parameters, string ParaType, object[] ParaValue)
        {
            return new DataAccessLayer().ExecProcedure(ProcedureName, parameters.Split(new char[] { ',' }), ParaType.Split(new char[] { ',' }), ParaValue);
        }

        /// <summary>
        /// 执行增删改存储过程
        /// </summary>
        /// <param name="commandtype">执行存储过程的类型（增删改）</param>
        /// <param name="ProcedureName">存储过程</param>
        /// <param name="parameters">参数数组</param>
        /// <param name="ParaType">参数数据类型数组（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="ParaValue">参数值对象数组</param>
        /// <returns>是否成功执行</returns>
        private static bool ExecProcedure(AccessCommand commandtype, string ProcedureName, string[] parameters, string[] ParaType, object[] ParaValue)
        {
            string msg = "";
            return (ExecProcedure(commandtype, ProcedureName, parameters, ParaType, ParaValue, out msg) > 0);
        }

        /// <summary>
        /// 执行查询存储过程(带参数)
        /// </summary>
        /// <param name="ProcedureName">存储过程名</param>
        /// <param name="parameters">参数数组</param>
        /// <param name="ParaType">参数数据类型数组（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="ParaValue">参数值对象数组</param>
        /// <param name="TableName">DataTable名</param>
        /// <returns>数据表</returns>
        public static DataTable ExecProcedure(string ProcedureName, string[] parameters, string[] ParaType, object[] ParaValue, string TableName)
        {
            return new DataAccessLayer().ExecProcedure(ProcedureName, parameters, ParaType, ParaValue, TableName);
        }

        /// <summary>
        /// 执行查询存储过程(带参数)
        /// </summary>
        /// <param name="ProcedureName">存储过程名</param>
        /// <param name="parameters">用","隔开的多个参数</param>
        /// <param name="ParaType">用","隔开的参数数据类型（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="ParaValue">参数值对象数组</param>
        /// <param name="TableName">DataTable名</param>
        /// <returns>数据表</returns>
        public static DataTable ExecProcedure(string ProcedureName, string parameters, string ParaType, object[] ParaValue, string TableName)
        {
            return ExecProcedure(ProcedureName, parameters.Split(new char[] { ',' }), ParaType.Split(new char[] { ',' }), ParaValue, TableName);
        }

        /// <summary>
        /// 执行增删改存储过程
        /// </summary>
        /// <param name="commandtype">执行存储过程的类型（增删改）</param>
        /// <param name="ProcedureName">存储过程</param>
        /// <param name="parameters">参数数组</param>
        /// <param name="ParaType">参数数据类型数组（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="ParaValue">参数值对象数组</param>
        /// <param name="msg">输出信息</param>   
        /// <returns>影响行数</returns>
        private static int ExecProcedure(AccessCommand commandtype, string ProcedureName, string[] parameters, string[] ParaType, object[] ParaValue, out string msg)
        {
            return new DataAccessLayer().ExecProcedure(commandtype, ProcedureName, parameters, ParaType, ParaValue, out msg);
        }

        /// <summary>
        /// 执行修改存储过程
        /// </summary>
        /// <param name="ProcedureName">存储过程</param>
        /// <param name="parameters">参数数组</param>
        /// <param name="ParaType">参数数据类型数组（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="ParaValue">参数值对象数组</param>
        /// <returns>是否成功执行</returns>
        public static bool ExecUpdateProcedure(string ProcedureName, string[] parameters, string[] ParaType, object[] ParaValue)
        {
            string msg = "";
            return (ExecProcedure(AccessCommand.Update, ProcedureName, parameters, ParaType, ParaValue, out msg) > 0);
        }

        /// <summary>
        /// 执行修改存储过程
        /// </summary>
        /// <param name="ProcedureName">存储过程</param>
        /// <param name="parameters">用","隔开的参数</param>
        /// <param name="ParaType">用","隔开的参数数据类型（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="ParaValue">参数值对象数组</param>
        /// <returns>是否成功执行</returns>
        public static bool ExecUpdateProcedure(string ProcedureName, string parameters, string ParaType, object[] ParaValue)
        {
            return ExecUpdateProcedure(ProcedureName, parameters.Split(new char[] { ',' }), ParaType.Split(new char[] { ',' }), ParaValue);
        }

        /// <summary>
        /// 执行修改存储过程
        /// </summary>
        /// <param name="commandtype">执行修改存储过程</param>
        /// <param name="ProcedureName">存储过程</param>
        /// <param name="parameters">参数数组</param>
        /// <param name="ParaType">参数数据类型数组（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="ParaValue">参数值对象数组</param>
        /// <param name="msg">输出信息</param>   
        /// <returns>影响行数</returns>
        public static int ExecUpdateProcedure(string ProcedureName, string[] parameters, string[] ParaType, object[] ParaValue, out string msg)
        {
            return ExecProcedure(AccessCommand.Update, ProcedureName, parameters, ParaType, ParaValue, out msg);
        }

        /// <summary>
        /// 执行修改(带参数)
        /// </summary>
        /// <param name="DBTable">数据库表名</param>
        /// <param name="parameters">更新字段名(用“,”隔开)</param>
        /// <param name="ParaValue">更新字段值对象数组</param>
        /// <param name="Wherepara">Where条件字段名(用“,”隔开)</param>
        /// <param name="WhereValue">Where条件字段值对象数组</param>
        /// <returns>是否成功执行</returns>
        public static bool ExecUpdateSQL(string DBTable, string parameters, object[] ParaValue, string Wherepara, object[] WhereValue)
        {
            return ExecUpdateSQL(DBTable, parameters.Split(new char[] { ',' }), ParaValue, Wherepara.Split(new char[] { ',' }), WhereValue);
        }

        /// <summary>
        /// 执行修改(带参数)
        /// </summary>
        /// <param name="DBTable">数据库表名</param>
        /// <param name="parameters">更新字段数组</param>
        /// <param name="ParaValue">更新字段值对象数组</param>
        /// <param name="Wherepara">Where条件字段数组</param>
        /// <param name="WhereValue">Where条件字段值对象数组</param>
        /// <returns>是否成功执行</returns>
        public static bool ExecUpdateSQL(string DBTable, string[] parameters, object[] ParaValue, string[] Wherepara, object[] WhereValue)
        {
            string msg = "";
            return (ExecUpdateSQL(DBTable, parameters, ParaValue, Wherepara, WhereValue, out msg) > 0);
        }

        /// <summary>
        /// 执行修改(带参数)
        /// </summary>
        /// <param name="DBTable">数据库表名</param>
        /// <param name="parameters">更新字段名(用“,”隔开)</param>
        /// <param name="ParaValue">更新字段值对象数组</param>
        /// <param name="Wherepara">Where条件字段名(用“,”隔开)</param>
        /// <param name="WhereValue">Where条件字段值对象数组</param>
        /// <param name="msg">输出信息</param>
        /// <returns>影响行数</returns>
        public static int ExecUpdateSQL(string DBTable, string parameters, object[] ParaValue, string Wherepara, object[] WhereValue, out string msg)
        {
            return ExecUpdateSQL(DBTable, parameters.Split(new char[] { ',' }), ParaValue, Wherepara.Split(new char[] { ',' }), WhereValue, out msg);
        }

        /// <summary>
        /// 执行修改(带参数)
        /// </summary>
        /// <param name="DBTable">数据库表名</param>
        /// <param name="parameters">更新字段数组</param>
        /// <param name="ParaValue">更新字段值对象数组</param>
        /// <param name="Wherepara">Where条件字段数组</param>
        /// <param name="WhereValue">Where条件字段值对象数组</param>
        /// <param name="msg">输出信息</param>
        /// <returns>影响行数</returns>
        public static int ExecUpdateSQL(string DBTable, string[] parameters, object[] ParaValue, string[] Wherepara, object[] WhereValue, out string msg)
        {
            return new DataAccessLayer().ExecUpdateSQL(DBTable, parameters, ParaValue, Wherepara, WhereValue, out msg);
        }

        /// <summary>
        /// 执行修改(带参数)
        /// </summary>
        /// <param name="DBTable">数据库表名</param>
        /// <param name="parameters">更新字段数组</param>
        /// <param name="ParaType">更新字段数据类型数组（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="ParaValue">更新字段值对象数组</param>
        /// <param name="Wherepara">Where条件字段数组</param>
        /// <param name="WhereType">Where条件字段数据类型数组（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="WhereValue">Where条件字段值对象数组</param>
        /// <returns>是否成功执行</returns>
        public static bool ExecUpdateSQL(string DBTable, string[] parameters, string[] ParaType, object[] ParaValue, string[] Wherepara, string[] WhereType, object[] WhereValue)
        {
            string msg = "";
            return (ExecUpdateSQL(DBTable, parameters, ParaType, ParaValue, Wherepara, WhereType, WhereValue, out msg) > 0);
        }

        /// <summary>
        /// 执行修改(带参数)
        /// </summary>
        /// <param name="DBTable">数据库表名</param>
        /// <param name="parameters">更新字段名(用“,”隔开)</param>
        /// <param name="ParaType">更新字段数据类型名(用“,”隔开)（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="ParaValue">更新字段值对象数组</param>
        /// <param name="Wherepara">Where条件字段名(用“,”隔开)</param>
        /// <param name="WhereType">Where条件字段数据类型(用“,”隔开)（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="WhereValue">Where条件字段值对象数组</param>
        /// <returns>是否成功执行</returns>
        public static bool ExecUpdateSQL(string DBTable, string parameters, string ParaType, object[] ParaValue, string Wherepara, string WhereType, object[] WhereValue)
        {
            return ExecUpdateSQL(DBTable, parameters.Split(new char[] { ',' }), ParaType.Split(new char[] { ',' }), ParaValue, Wherepara.Split(new char[] { ',' }), WhereType.Split(new char[] { ',' }), WhereValue);
        }

        /// <summary>
        /// 执行修改(带参数)
        /// </summary>
        /// <param name="DBTable">数据库表名</param>
        /// <param name="parameters">更新字段名(用“,”隔开)</param>
        /// <param name="ParaType">更新字段数据类型名(用“,”隔开)（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="ParaValue">更新字段值对象数组</param>
        /// <param name="Wherepara">Where条件字段名(用“,”隔开)</param>
        /// <param name="WhereType">Where条件字段数据类型(用“,”隔开)（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="WhereValue">Where条件字段值对象数组</param>
        /// <param name="msg">输出信息</param>
        /// <returns>影响行数</returns>
        public static int ExecUpdateSQL(string DBTable, string parameters, string ParaType, object[] ParaValue, string Wherepara, string WhereType, object[] WhereValue, out string msg)
        {
            return ExecUpdateSQL(DBTable, parameters.Split(new char[] { ',' }), ParaType.Split(new char[] { ',' }), ParaValue, Wherepara.Split(new char[] { ',' }), WhereType.Split(new char[] { ',' }), WhereValue, out msg);
        }

        /// <summary>
        /// 执行修改(带参数)
        /// </summary>
        /// <param name="DBTable">数据库表名</param>
        /// <param name="parameters">更新字段数组</param>
        /// <param name="ParaType">更新字段数据类型数组（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="ParaValue">更新字段值对象数组</param>
        /// <param name="Wherepara">Where条件字段数组</param>
        /// <param name="WhereType">Where条件字段数据类型数组（eg：int,string,datetime,double,image,bit,guid,text,ntext）</param>
        /// <param name="WhereValue">Where条件字段值对象数组</param>
        /// <param name="msg">输出信息</param>
        /// <returns>影响行数</returns>
        public static int ExecUpdateSQL(string DBTable, string[] parameters, string[] ParaType, object[] ParaValue, string[] Wherepara, string[] WhereType, object[] WhereValue, out string msg)
        {
            return new DataAccessLayer().ExecUpdateSQL(DBTable, parameters, ParaType, ParaValue, Wherepara, WhereType, WhereValue, out msg);
        }

        public static bool ExecuteTransaction(string SQL)
        {
            string msg = "";
            return new DataAccessLayer().ExecuteTransaction(SQL, out msg);
        }

        /// <summary>
        /// 执行事务
        /// </summary>
        /// <param name="SQL">SQL语句</param>
        /// <param name="msg">输出影响行数信息</param>
        /// <returns>是否成功执行</returns>
        public static bool ExecuteTransaction(string SQL, out string msg)
        {
            return new DataAccessLayer().ExecuteTransaction(SQL, out msg);
        }

        /// <summary>
        /// 获取DataTable
        /// </summary>
        /// <param name="SQL">SQL语句</param>
        /// <returns>DataTable</returns>
        public static DataRow GetDataRow(string SQL)
        {
            try
            {
                return new DataAccessLayer().GetTable(SQL, "tablename").Rows[0];
            }
            catch
            {
                return null;
            }
        }

        /// <summary>
        /// 获取DataSet
        /// </summary>
        /// <param name="SQL">SQL语句</param>
        /// <returns></returns>
        public static DataSet GetDataSet(string SQL)
        {
            return new DataAccessLayer().GetDataSet(SQL);
        }

        /// <summary>
        /// 获取SQL查询结果第一行第一列值
        /// </summary>
        /// <param name="SQL">SQL语句</param>
        /// <returns>查询结果</returns>
        public static string GetString(string SQL)
        {
            return new DataAccessLayer().GetString(SQL);
        }

        /// <summary>
        /// 获取SQL查询结果指定字段首行值
        /// </summary>
        /// <param name="SQL">SQL语句</param>
        /// <param name="Field">字段名</param>
        /// <returns>查询结果</returns>
        public static string GetString(string SQL, string Field)
        {
            return new DataAccessLayer().GetString(SQL, Field);
        }

        /// <summary>
        /// 获取固定表查询结果指定字段首行值
        /// </summary>
        /// <param name="Table">表名</param>
        /// <param name="Field">字段名</param>
        /// <param name="Where">筛选条件</param>
        /// <returns>查询结果</returns>
        public static string GetString(string Table, string Field, string Where)
        {
            return new DataAccessLayer().GetString(Table, Field, Where);
        }

        /// <summary>
        /// 获取DataTable
        /// </summary>
        /// <param name="SQL">SQL语句</param>
        /// <returns>DataTable</returns>
        public static DataTable GetTable(string SQL)
        {
            return new DataAccessLayer().GetTable(SQL, "tablename");
        }

        /// <summary>
        /// 获取DataTable
        /// </summary>
        /// <param name="SQL">SQL语句</param>
        /// <param name="name">DataTable表名</param>
        /// <returns>DataTable</returns>
        public static DataTable GetTable(string SQL, string name)
        {
            return new DataAccessLayer().GetTable(SQL, name);
        }

        /// <summary>
        /// 获取DataSet
        /// </summary>
        /// <param name="SQL">SQL语句</param>
        /// <returns></returns>
        public static DataSet GetTables(string SQL)
        {
            return new DataAccessLayer().GetDataSet(SQL);
        }

        /// <summary>
        /// 数据插入
        /// </summary>
        /// <param name="SQL">SQL语句</param>
        /// <param name="msg">输出信息</param>
        /// <returns>是否成功保存</returns>
        public static bool Insert(string SQL, out string msg)
        {
            return new DataAccessLayer().Insert(SQL, out msg);
        }

        /// <summary>
        /// 数据插入(输出自动编号)
        /// </summary>
        /// <param name="SQL">SQL语句</param>
        /// <param name="ID">新增自动编号字段值</param>
        /// <param name="msg">输出信息</param>
        /// <returns>是否成功保存</returns>
        public static bool Insert(string SQL, out int ID, out string msg)
        {
            return new DataAccessLayer().Insert(SQL, out ID, out msg);
        }

        /// <summary>
        /// 插入数据表
        /// </summary>
        /// <param name="SQL">需要插入表SQL语句</param>
        /// <param name="dtInsert">插入的DataTable</param>
        /// <param name="msg">输出信息</param>
        /// <returns>是否成功插入</returns>
        public static bool InsertDataTable(string SQL, DataTable dtInsert, out string msg)
        {
            return new DataAccessLayer().InsertDataTable(SQL, dtInsert, out msg);
        }

        /// <summary>
        /// 查询记录是否存在
        /// </summary>
        /// <param name="SQL">SQL语句</param>
        /// <returns>查询结果</returns>
        public static bool IsExist(string SQL)
        {
            DataTable table = new DataAccessLayer().GetTable(SQL, "");
            if ((table != null) && (table.Rows.Count < 1))
            {
                return false;
            }
            return true;
        }

        /// <summary>
        /// 防范SQL注入式攻击(拼接前校验参数)
        /// </summary>
        /// <param name="strSQL">拼接字符串参数</param>
        /// <returns></returns>
        public static bool IsHack(string strSQL)
        {
            if (strSQL.Length != 0)
            {
                string[] strArray = new string[] { 
                    "CAST ( ", "CAST( ", "DECLARE ", "SELECT ", "DELETE ", "INSERT ", "UPDATE ", "DROP ", "TRUNCATE ", "NET ", "XP_CMDSHELL ", "/ADD ", "EXEC ", "--", "=", "<>", 
                    ">", "<", "!=", "ALTER ", "CREATE "
                 };
                for (int i = 0; i < strArray.Length; i++)
                {
                    if (strSQL.ToUpper().IndexOf(strArray[i]) != -1)
                    {
                        return true;
                    }
                }
            }
            return false;
        }

        /// <summary>
        /// 数据更新
        /// </summary>
        /// <param name="SQL">SQL语句</param>
        /// <param name="msg">输出信息</param>
        /// <returns>是否成功保存</returns>
        public static bool Update(string SQL, out string msg)
        {
            return new DataAccessLayer().Update(SQL, out msg);
        }
    }
}

